import React from 'react';
import type { MenuDataItem } from '@ant-design/pro-layout';
import * as allIcons from '@ant-design/icons';
// 处理菜单Icon
const fixMenuItemIcon = (menus: MenuDataItem[], iconType = 'Outlined'): MenuDataItem[] => {
  menus.forEach((menu) => {
    const { icon, routes } = menu;
    if (typeof icon === 'string') {
      const fixIcon = icon.slice(0, 1).toLocaleUpperCase() + icon.slice(1) + iconType;
      menu.icon = React.createElement(allIcons[fixIcon] || allIcons[icon]);
    }
    if (routes && routes.length > 0) {
      menu.routes = fixMenuItemIcon(routes);
    }
  });
  console.log('菜单数据', menus);

  return menus;
};

export default fixMenuItemIcon;

// const IconMap = {
//   smile: <SmileOutlined />,
//   heart: <HeartOutlined />,
//   setting: <SettingOutlined />,
//   menuUnfold: <MenuUnfoldOutlined />,
// };

// // 处理菜单Icon
// const loopMenuItem = (menus: MenuDataItem[]): MenuDataItem[] =>
//   menus.map(({ icon, routes, ...item }) => ({
//     ...item,
//     icon: icon && IconMap[icon as string],
//     routes: routes && loopMenuItem(routes),
//   }));
